package com.firsteapps.mobile.android.puzzle;

import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.firsteapps.mobile.android.puzzle.game.Helper;
import com.firsteapps.mobile.android.puzzle.util.Utilities;

public class PostLoginBase extends BaseActivity {
	private final String TAG = "PostLoginBase";

	private String workingDirectory = null;

	protected String getWorkingDirectory() {
		return workingDirectory;
	}

	protected String getWorkingSubDirectory(String subFolder) {
		return getWorkingDirectory() == null ? null : getWorkingDirectory() + subFolder;
	}

	protected void setWorkingDirectory(String workingDirectory) {
		this.workingDirectory = workingDirectory;
	}

	@Override
	protected void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		Log.d(TAG, "onCreate");

		setWorkingDirectory(getWorkingDirectoryBase());
		if (getWorkingDirectory() == null) {
			Helper.doMessageDialog(PostLoginBase.this, getClass().getName(),
					"You are not logged in and will be redirected to login page.", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							Utilities.startActivityWithAnimation(PostLoginBase.this, SelectProfile.class);
						}
					}, false);
		}

	}

	@Override
	protected void onPostCreate(Bundle savedInstanceState) {
		super.onPostCreate(savedInstanceState);
		Log.d(TAG, "onPostCreate");

		TextView username_top = (TextView) findViewById(R.id.username_field_top);
		if (username_top != null && getUserName() != null) {
			username_top.setText(Helper.getUserName(getUserName()));
		}
		TextView username_bottom = (TextView) findViewById(R.id.username_field_botom);
		if (username_bottom != null && getUserName() != null) {
			username_bottom.setText(Helper.getUserName(getUserName()));
		}
		
		TextView creditBalanceField = (TextView) findViewById(R.id.credit_balance_field);
		if (creditBalanceField != null) {
			creditBalanceField.setText(getCreditBalance() > 0 ? "" + getCreditBalance() : "0");
		}
	}

	@Override
	protected void onPause() {
		super.onPause();
		Log.d(TAG, "onPause");
	}

	@Override
	protected void onResume() {
		super.onResume();
		Log.d(TAG, "onResume");
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		Log.d(TAG, "onDestroy");
	}
}